-
Notifications
You must be signed in to change notification settings - Fork 112
Conversation
bitswap.go
Outdated
select { | ||
case <-bs.process.Closing(): | ||
return errors.New("bitswap is closed") | ||
default: | ||
} | ||
|
||
wanted := blks | ||
// NOTE: There exists the possibility for a race condition here. If a user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this PR split receiveBlocksFrom
into two cases:
- block added from the node
- block added from the network
Not only this make the code much clearer, it also segregate the problem mentioned in this comment in a single code path.
cc @Jorropo |
@MichaelMure i dont think its quite the right thingy to do here. Afait bitswap was dedupping concurrent getblocks while what you propose would have a put per getblock. I think bitswap should do puts but only when the block is receved from the network. Or am I missing something here ? |
I believe this is still happening, the same way it was done before:
The diff in the PR is quite unreadable, I'd suggest looking at the resulting code where it's much clearer.
This PR removes the put done in One thing that this PR does change is that Puts are no longer batched together, or rather no longer batched the same way. Before, there would be a |
Not sure what's happening with the CI, test are OK for me locally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a strict improvement. Thank you!
bitswap.go
Outdated
// creates a node, then adds it to the dagservice while another goroutine | ||
// is waiting on a GetBlock for that object, they will receive a reference | ||
// to the same node. We should address this soon, but i'm not going to do | ||
// it now as it requires more thought and isn't causing immediate problems. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. You're copying a comment. This isn't an issue, you can remove it.
bitswap.go
Outdated
@@ -469,60 +469,68 @@ func (bs *Bitswap) GetBlocks(ctx context.Context, keys []cid.Cid) (<-chan blocks | |||
func (bs *Bitswap) HasBlock(ctx context.Context, blk blocks.Block) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's document that the block must exist in the blockstore.
I need to re-review this. I missed a few things.
Unfortunately, it looks like this will act like we have a block before that block actually gets written locally. I.e., on receive, we'll:
This creates a race where we might, in some cases (performance, canceled requests, etc.) fail to send blocks to peer when we have them. As discussed in person (written here so we're on the same page), a simple solution is to just not tell the network anything until the blockservice calls
Basically, this is the same as this PR but taken to the extreme. The receive side is completely disconnected from the send side (except for the bandwidth ledger). Changes required:
Tricky parts:
|
I like that idea. Does that sounds good to you? Anything else? // Interface defines the functionality of the IPFS block exchange protocol.
type Interface interface { // type Exchanger interface
Fetcher
- // TODO Should callers be concerned with whether the block was made
- // available on the network?
- HasBlock(context.Context, blocks.Block) error
+ // NotifyNewBlocks tells the exchange that a new block is available and can be served.
+ NotifyNewBlocks(ctx context.Context, block blocks.Block) error
IsOnline() bool
io.Closer
} |
I'd make it take multiple blocks (or have a second function that takes multiple blocks), but yeah, something like that. |
The goal here is twofold: - allows for batched handling of multiple blocks at once - act as a noisy signal for the breaking change that Bitswap is not adding blocks in the blockstore itself anymore (see ipfs/go-bitswap#571)
@Stebalien let's make it variadic then: ipfs/go-ipfs-exchange-interface#23 |
20d8197
to
2c2a461
Compare
@Stebalien I think I'm done now, tests are green at least on some platform, but I don't fully know what I'm doing here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not at all confident that this code works completely correctly,
However I think it's good enough to be dog-fooded in Kubo.
LGTM
This leave the responsibility and choice to do so to the caller, typically go-blockservice. This has several benefit: - untangle the code - allow to use an exchange as pure block retrieval - avoid double add Close ipfs/kubo#7956
Don't add blocks to the datastore This commit was moved from ipfs/go-bitswap@1d1c6bf
This leave the responsibility and choice to do so to the caller, typically go-blockservice.
This has several benefit:
Close ipfs/kubo#7956